package bishihuizong;
import java.io.*;
/**
 * Created by JiaJia on 2019/9/22 0022.
 */
public class Vivo02 {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String inputStr = br.readLine();
        int input[] = parseInts(inputStr.split(" "));
        int output = solution(input);
        System.out.println(output);
    }

    private static int[] parseInts(String[] strArr) {
        if (strArr == null || strArr.length == 0) {
            return new int[0];
        }
        int[] intArr = new int[strArr.length];
        for (int i = 0; i < intArr.length; i++) {
            intArr[i] = Integer.parseInt(strArr[i]);
        }
        return intArr;
    }

    private static int solution(int[] input) {
        int sum=conputeSum(input);
        //int w=sum/2;
        int n2=input.length;
        int n=n2/2;
        int result=0;
        boolean[][] flag=new boolean[input.length+1][sum/2+1];
        for (int i = 0; i <input.length ; i++) {
            for (int j = 0; j <sum/2+1 ; j++) {
                flag[i][j]=false;
            }
        }
        flag[0][0]=true;
        for (int k = 0; k <n2 ; k++) {
            for (int i = k>n?n:k; i >=1 ; i--) {
                for (int j = 0; j <=sum/2 ; j++) {
                    if (j>input[k]&&flag[i-1][j-input[k]])
                        flag[i][j]=true;
                }
            }
        }
        for (int j =sum/2;j>=0 ; j++) {
            if (flag[n][j]){
                result=Math.abs(2*j-sum);
            }
        }
        return result;


    }
    private static int conputeSum(int[] input){
        int sum=0;
        for(int num:input){
            sum+=num;
        }
        return sum;
    }
}